package tcln.gxtx.client.utils.date;

import java.util.Date;

/**
 * Default implementation for {@link GwtDate} using emulated {@link Date}.
 * 
 * @author Truong Chau Lien Ngoc (lienngoc@gmail.com)
 */
public class DefaultGwtDateImpl extends DefaultGwtDateInstant implements GwtDate {

    DefaultGwtDateImpl() {
        super();
        clearTimePortions();
    }

    DefaultGwtDateImpl(Date inner) {
        super(inner);
        clearTimePortions();
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public int compareTo(DefaultGwtDateInstant o) {
        if (o instanceof GwtDate) {
            return super.compareTo(o);
        }
        return 1;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public String toString() {
        return toString(DEFAULT_DATE_FORMAT);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public boolean after(GwtDate another) {
        if (another instanceof GwtDateInstant) {
            return isAfter((GwtDateInstant) another);
        }
        return false;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public boolean before(GwtDate another) {
        if (another instanceof GwtDateInstant) {
            return isBefore((GwtDateInstant) another);
        }
        return false;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public boolean between(GwtDate lower, GwtDate upper) {
        if (lower instanceof GwtDateInstant && upper instanceof GwtDateInstant) {
            return isBetween((GwtDateInstant) lower, (GwtDateInstant) upper);
        }
        return false;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public boolean betweenExclusive(GwtDate lower, GwtDate upper) {
        if (lower instanceof GwtDateInstant && upper instanceof GwtDateInstant) {
            return isBetweenExclusive((GwtDateInstant) lower, (GwtDateInstant) upper);
        }
        return false;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public boolean equals(GwtDate another) {
        if (another instanceof GwtDateInstant) {
            return isEqualTo((GwtDateInstant) another);
        }
        return false;
    }
}
